package servlets;
import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import utility.UserSession;

public class ChangePassword extends HttpServlet{
public ChangePassword(){
	super();
	System.out.println("\n\n\n In credit card");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{
	
        response.setContentType("text/html");
        String oldPassword= request.getParameter("password");
        String newPassword=request.getParameter("newpassword");
        UserSession sess = new UserSession();
        String message = null;
		try {
			message = sess.changePassword(oldPassword,newPassword);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        if(message.equals("Success"))
        {
       	 request.setAttribute("message", "Password changed Successfully");
       	RequestDispatcher RequestDispatcherObj =request.getRequestDispatcher("/view/UserHome.jsp");
        RequestDispatcherObj.forward(request, response);
        }
        else
        {
        	request.setAttribute("message", "Your current password is wrong");
           	RequestDispatcher RequestDispatcherObj =request.getRequestDispatcher("/view/AccountInfo.jsp");
            RequestDispatcherObj.forward(request, response);
        }
}
}